package com.bustle.user.proxy;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.commons.XmlParser;
import com.bustle.commons.data.dao.Dao;
import com.bustle.commons.data.dao.DaoProxy;
import com.bustle.commons.http.RestDtoDaoProxy;
import com.bustle.commons.http.TypeToXmlHttpConverter;
import com.bustle.user.dto.authentication.AuthenticationDto;
import com.bustle.user.dto.authentication.AuthenticationDtoDaoWebService.AuthenticationDtoList;
import com.bustle.user.dto.authentication.AuthenticationDtoMapper;

@Local
public interface AuthenticationDtoDaoProxy extends Dao<String, AuthenticationDto>
{
  @Stateless
  public class DefaultAuthenticationDtoDaoProxy extends DaoProxy<String, AuthenticationDto, Dao<String, AuthenticationDto>> implements AuthenticationDtoDaoProxy
  {
    @PostConstruct
    public void postBuild()
    {
      dao = new RestDtoDaoProxy<String, AuthenticationDto>("localhost", 8080, "authentication", new XmlParser(), new TypeToXmlHttpConverter<>(AuthenticationDto.class), AuthenticationDto.class, dtoMapper)
        {
          @Override
          protected List<AuthenticationDto> retrieveAllFrom(String aResult)
          {
            return parser.parse(AuthenticationDtoList.class, aResult).getAuthentication();
          }
        };
    }

    @EJB
    protected AuthenticationDtoMapper dtoMapper;
  }
}
